package codegen.config;

import cn.hutool.core.util.StrUtil;
import com.mybatisflex.codegen.entity.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CommonCustomConfig implements Serializable {
    private String classPrefix = "";
    private String classSuffix = "";
    private String prefixDir = "";
    private boolean overwriteEnable;
    private boolean genEnable;

    public String getIndexHtmlFileName(Table table) {
        String entityJavaFileName = table.getEntityJavaFileName();
        if (entityJavaFileName.toLowerCase().startsWith("system")) {
            entityJavaFileName = entityJavaFileName.substring(6);
        }
        return StrUtil.lowerFirst(StringUtils.defaultString(classPrefix) + entityJavaFileName +
                StringUtils.defaultString(classSuffix));
    }
}
